<?php
namespace Shopiuu\Model;

use Shopiuu\Http\RequestCore;

class Payment extends Model{
    
    public function __construct($accessToken, $endpoint)
    {
        parent::__construct($accessToken, $endpoint);
    }

    /**
     * Create payment
     * @param array $params array(
        "name"=> "PayPal" //支付方式名称
        "interface"=> "paypalcheckout" //支付方式接口
        "fee_interface"=> "paymentfee_percent_fixed" //支付方式接口
        "status"=> "1" //状态， 1 开启 0 关闭
        "payment_param"=> array(
            "account":"test@paypal.com"
            "client_id":""
            "secret":""
            "is_sandbox":"1"
            "tracking_send":"1"
            "brand":"shop"
            "payment_mode":"CAPTURE"
            "express":"1"
            "smart_button":"1"
        )
        "fee_param"=> array(
            "percent"=> 0
        )
        "display_param"=> array(
            "amount_max"=> ""
            "amount_min"=> ""
            "country_whitelist"=> ""
            "country_blacklist"=> ""
        )
        "image"=> "//image.example.com/Upload/1/payment/2021-05-31/55d8d850af608994.jpg" // 支付图片
        "discount_descript"=> "" //折扣说明
        "account_descript"=> "" //收款账号说明
        "details"=> "" //支付说明
        "sort"=> "0" //排序
        "collect_image"=> "1" //是否采集图片
        )
     * @return ResponseCore
     */
    public function add($params)
    {
        $request = $this->getRequest('/openApi/payment/add');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }

    /**
     * Modify payment
     * @param array $paramss array(
        "id":"25" //支付方式id
        "name"=> "PayPal" //支付方式名称
        "interface"=> "paypalcheckout" //支付方式接口
        "fee_interface"=> "paymentfee_percent_fixed" //支付方式接口
        "status"=> "1" //状态， 1 开启 0 关闭
        "payment_param"=> array(
            "account":"test@paypal.com"
            "client_id":""
            "secret":""
            "is_sandbox":"1"
            "tracking_send":"1"
            "brand":"shop"
            "payment_mode":"CAPTURE"
            "express":"1"
            "smart_button":"1"
        )
        "fee_param"=> array(
            "percent"=> 0
        )
        "display_param"=> array(
            "amount_max"=> ""
            "amount_min"=> ""
            "country_whitelist"=> ""
            "country_blacklist"=> ""
        )
        "image"=> "//image.example.com/Upload/1/payment/2021-05-31/55d8d850af608994.jpg" // 支付图片
        "discount_descript"=> "" //折扣说明
        "account_descript"=> "" //收款账号说明
        "details"=> "" //支付说明
        "sort"=> "0" //排序
        "collect_image"=> "1" //是否采集图片
        )
     * @return ResponseCore
     */
    public function update($params)
    {
        $request = $this->getRequest('/openApi/payment/update');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }

    /**
     * Get payments
     * @param array $params array(
        "pagenum"=> 1 //页码
        "pagesize"=> 20 //每页数量
        "search"=> "keywords" //搜索标题
        "interface"=> "paypalcheckout" //接口类型搜索
        "orderfeild"=> "id" //排序字段
        "ordersort"=> "desc" //排序方式
        "status"=> 1 //状态搜索
     )
     * @return ResponseCore
     */
    public function getList($params)
    {
        $request = $this->getRequest('/openApi/payment/lists');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }

    /**
     * Get all payments
     * @param array $params array(
        "search"=> "keywords" //搜索标题
        "interface"=> "paypalcheckout" //接口类型搜索
        "orderfeild"=> "id" //排序字段
        "ordersort"=> "asc" //排序方式
        "status"=> 1 //状态搜索
     )
     * @return ResponseCore
     */
    public function getAllPayments($params)
    {
        $request = $this->getRequest('/openApi/payment/getAllPayments');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }
    
    /**
     * Delete payment
     * @param array $params array("id"=>"25")
     * @return ResponseCore
     */
    public function delete($params)
    {
        $request = $this->getRequest('/openApi/payment/delete');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }

}